package com.parent.api_entity.aliyun;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author yan
 * @Date 2023/6/28 0028 10:38
 * @Description
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
public class OssUrl {
    /**
     * 域名
     */
    private String endpoint;
    /**
     * 桶
     */
    private String bucketName;
    /**
     * 文件路径
     */
    private String filePath;

    public OssUrl(String url) {
        int firstIndex = url.indexOf('/', url.indexOf('/') + 1);
        int secondIndex = url.indexOf('/', firstIndex + 1);
        String result = url.substring(firstIndex + 1, secondIndex);
        String imageBucketName = result.substring(0, result.indexOf("."));
        String ossEndpoint = result.substring(result.indexOf(".") + 1, result.length());

        int Index = url.indexOf('/', url.indexOf('/') + 2);
        String filePath = url.substring(Index + 1, url.length());

        this.endpoint = ossEndpoint;
        this.bucketName = imageBucketName;
        this.filePath = filePath;
    }
}
